package com.fysports.web.controller.user;

import com.google.common.collect.Lists;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Page;
import com.fysports.web.controller.engine.AutoRestFulController;
import com.fysports.web.kit.dtgrid.DTGridView;
import com.fysports.web.model.user.UserFavorite;

import java.util.List;


/**
 * Class title:  用户收藏管理  <br/>
 * Describe:                    <br/>
 * Created by konbluesky           <br/>
 * Date : 16/1/6 下午5:15       <br/>
 * Project : weixin    <br/>
 */
public class UserFavoriteController extends AutoRestFulController<UserFavorite> {
    private static Log log = Log.getLog(UserFavoriteController.class);


    @Override public void load() {
        String useruuid=getPara();
        DTGridView view = getGridView();
        String sql="select uf.*,u.memberid,p.name ";
        String sqlext=" from user_favorite as uf "
                + " right join user as u on u.uuid=uf.useruuid "
                + " left join product as p on uf.productuuid=p.uuid "
                + " where u.uuid=?";
        List<Object> params= Lists.newArrayList();
        params.add(useruuid);
        Page<UserFavorite> list =
                UserFavorite.dao.DTSearchPaginate(view.getNowPage(), view.getPageSize(), sql, sqlext, null, params);
        renderJson(toGridView(view, list));
    }


    @Override protected UserFavorite getCtrModel() {
        return UserFavorite.dao;
    }


    @Override protected String getRenderPath() {
        return "user/favorite/favorite_";
    }
}
